#!/usr/bin/env python
# -*- encoding: utf-8 -*-
# Project: mysql ddl to yaml
# 实现菜单解析
import sys

from com.generator.utils import snake_to_camel_case, getTableName

class Meta:
    def __init__(self, name, comment, fields):
        self.name = name
        self.comment = comment
        self.fields = fields

    name = ''
    comment = ''
    fields = []


class Field:
    name = ''
    type = ''
    comment = ''
    require = False
    binding_options = ""
    gorm_options = ""

    def __init__(self, name, type, comment, require, binding_options, gorm_options):
        self.name = snake_to_camel_case(name)
        self.type = self.parseType(type)
        self.comment = comment
        self.require = self.parseRequire(require)
        self.binding_options = binding_options
        self.gorm_options = gorm_options

    def parseType(self, type):
        if type in ["char", "varchar", "text"]:
            return "string"
        elif type == "tinyint":
            return "int8"
        elif type == "int":
            return "int32"
        elif type == "bigint":
            return "int64"
        elif type == "smallint":
            return "int16"
        elif type in ["timestamp", "datetime"]:
            return "time.Time"
        elif type == "decimal":
            return "decimal.Decimal"
        else:
            return "string"

    def parseRequire(self, require):
        return False if require == "YES" else True

    def parseName(self, name):
        return snake_to_camel_case(getTableName(name))



if __name__ == '__main__':
    column_name = "calc_princ"
    f = Field(column_name, "varchar", column_name, "YES", "", "")
    print(f.__dict__)
